<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<%
	String path = request.getContextPath();
	response.setContentType("text/html;charset=utf-8");
	response.setCharacterEncoding("utf-8");
%>
<%@taglib prefix="shiro" uri="http://shiro.apache.org/tags"%>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta name="copyright" content="" />
<meta name="keywords" content="" />
<meta name="description" content="" />
<title>业务编辑</title>
<link href="<%=path%>/favicon.ico" rel="shortcut icon">

<link rel="stylesheet" type="text/css"
	href="<%=path%>/css/marketing/public.css" />
<link rel="stylesheet" type="text/css"
	href="<%=path%>/css/marketing/style_list.css" />


<link href="<%=path%>/hplus/css/bootstrap.min14ed.css?v=3.3.6"
	rel="stylesheet">
<link href="<%=path%>/hplus/css/font-awesome.min93e3.css?v=4.4.0"
	rel="stylesheet">
<link href="<%=path%>/hplus/css/plugins/iCheck/custom.css"
	rel="stylesheet">
<link href="<%=path%>/hplus/css/animate.min.css" rel="stylesheet">
<link href="<%=path%>/hplus/css/style.min862f.css?v=4.1.0"
	rel="stylesheet">
<link rel="stylesheet" type="text/css"
	href="<%=path%>/hplus/js/plugins/sweetalert/sweetalert2.min.css">
<link href="<%=path%>/css/marketing/s_style.css" rel="stylesheet">

</head>
<body class="gray-bg">
	<div class="wrapper wrapper-content animated fadeInRight">
		<div class="container-fluid">
			<div class="row">
				<div class="col-md-1"></div>
				<div class="col-md-10 white-bg">
					<div class="row">
						<div style="height: 40px">
							<center>
								<h4 style="padding-top: 10px;">编辑业务介绍</h4>
							</center>
						</div>
						<div class="gray-bg" style="padding-bottom: 5px;"></div>
						<div style="padding-left: 90px; width: 90%">
							<div id="editor"></div>
							<h3>&nbsp;</h3>
							<form method="get"
								class="form-horizontal m-t commithtml text-center"></form>
						</div>
						<div class="gray-bg" style="padding-bottom: 10px;"></div>
						<div style="height: 10px"></div>
						<div style="height: 25px">
							<center>
								<b>编辑显示卡片</b>
							</center>
						</div>
						<div class="gray-bg" style="padding-bottom: 10px;"></div>
						<div style="height: 180px;">
							<div class="row"
								style="padding-left: 90px; padding-top: 15px; float: left;">
								<form id='pic_' action="post"
									class="form-vertical m-t text-left col-md-6"
									enctype='multipart/form-data'>
									<div class="x_img_sc">
										<img id="img3" src="<%=path%>/images/marketing/img_p.png"
											style="width: 120px; height: 120px;">
									</div>
									<input type="file" accept="image/gif,image/jpeg,image/x-png"
										id="p_inputfile" onchange="fileloadon('pic')" name="filepath"
										style="filter: alpha(opacity = 50); -moz-opacity: 0.5; -khtml-opacity: 0.5; opacity: 0.0; position: absolute; z-index: 99; width: 120px; height: 120px;">
								</form>
							</div>
							<div
								style="padding-left: 270px; padding-top: 25px; padding-right: 90px;">
								<input id="title" class="form-control" maxlength="18" placeholder="编辑标题" />
								<div style="padding-top: 10px;"></div>
								<div>
								<textarea style="width: 100%;" id="content" maxlength="66"
									class="panel panel-default panel-body col-sm-6"
									placeholder="编辑简介"></textarea>
									</div>
							</div>
						</div>
						<div class="gray-bg" style="padding-bottom: 10px;"></div>
						<div style="height: 10px"></div>
						<div style="height: 25px">
							<center>
								<b>尾页二维码</b>
							</center>
						</div>
						<div class="gray-bg" style="padding-bottom: 10px;"></div>
						<div style="height: 180px;">
						<table>
							<tr>
								<td style="width: 222px;"></td>
								<td></td>
								<td></td>
								<td><div>
								<form id='_weixin_qrcode'
									action="post"
									class="form-vertical m-t text-left col-md-6"
									enctype='multipart/form-data'>
									<div class="row">
										<div class="x_img_sc">
											<img id="img4" src="<%=path%>/images/marketing/img_p.png"
												style="width: 100px; height: 100px;">
										</div>
										<input type="file" accept="image/gif,image/jpeg,image/x-png"
											id="x_inputfile" onchange="fileloadon('weixin')"
											name="filepath"
											style="filter: alpha(opacity = 50); -moz-opacity: 0.5; -khtml-opacity: 0.5; opacity: 0.0; position: absolute; z-index: 99;">
									</div>

								</form>
					</div></td>
								<td></td>
								<td></td>
								<td></td>
								<td><div>
								<form id='_weibo_qrcode'
									enctype='multipart/form-data' action="post"
									class="form-vertical m-t text-left col-md-6">
									<div class="row">
										<div class="x_img_sc">
											<img id="img5" src="<%=path%>/images/marketing/img_p.png"
												style="width: 100px; height: 100px;" />
										</div>
										<input type="file" accept="image/gif,image/jpeg,image/x-png"
											id="b_inputfile" onchange="fileloadon('weibo')"
											name="filepath"
											style="filter: alpha(opacity = 50); -moz-opacity: 0.5; -khtml-opacity: 0.5; opacity: 0.0; position: absolute; z-index: 99; height: 100px; width: 100" />
									</div>

								</form>
							</div></td>
								<td></td>
								<td></td>
								<td></td>
							</tr>
							<tr>
								<td></td>
								<td></td>
								<td></td>
								<td><div>&nbsp;
								<label class="checkbox-inline i-checks"
									style="margin-left: -9px; margin-top: 5px"><input
									id="input_weixin" type="checkbox" value="weixin2">微信二维码</label>
							</div></td>
								<td></td>
								<td></td>
								<td></td>
								<td><div>&nbsp;
								<label class="checkbox-inline i-checks"
									style="margin-left: -9px; margin-top: 5px"> <input
									id="input_weibo" type="checkbox" value="weibo2">微博二维码
								</label>
							</div></td>
								<td></td>
								<td></td>
								<td></td>
							</tr>
						</table>
						</div>
						<div class="gray-bg" style="padding-bottom: 15px;"></div>
						<div style="height: 70px;">
							<center>
								<button class="btn btn-primary" onclick="back_()"
									style="margin-top: 18px; margin-right: 5px;">返回</button>
								<button class="btn btn-primary" onclick="preview_()"
									style="margin-top: 18px; margin-right: 5px;">预览</button>
								<button class="btn btn-primary" onclick="save()"
									style="margin-top: 18px;">保存</button>
							</center>
						</div>
						<div class="gray-bg" style="padding-bottom: 80px;"></div>
					</div>
				</div>
				<div class="col-md-1"></div>
			</div>

		</div>
	</div>


	<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/2.2.4/jquery.min.js"></script>

	<script type="text/javascript"
		src="<%=path%>/js/marketing/ajaxfileupload.js"></script>
	<script
		src="https://cdnjs.cloudflare.com/ajax/libs/jquery-cookie/1.4.1/jquery.cookie.min.js"></script>
	<script type="text/javascript"
		src="<%=path%>/js/marketing/lengthlimit.js"></script>


	<script src="<%=path%>/hplus/js/bootstrap.min.js?v=3.3.6"></script>
	<script src="<%=path%>/hplus/js/plugins/iCheck/icheck.min.js"></script>
	<script src="<%=path%>/hplus/js/plugins/sweetalert/sweetalert2.min.js"></script>
	<script type="text/javascript" src="<%=path%>/js/marketing/dialog.js"></script>
	<script
		src="https://cdnjs.cloudflare.com/ajax/libs/datatables/1.10.16/js/jquery.dataTables.min.js"></script>
	<%--<script type="text/javascript"--%>
		<%--src="<%=path%>/js/marketing/ckeditor/ckeditor.js"></script>--%>
	<script type="text/javascript" src="<%=path%>/js/marketing/ckeditor/ckeditor.js"></script>

	<script type="text/javascript" src="<%=path%>/js/marketing/ckeditor/sample.js"></script>

	<script
		src="https://cdnjs.cloudflare.com/ajax/libs/jquery.form/4.2.2/jquery.form.min.js"></script>
	<script type="text/javascript">

	//单选按钮
    $('#input_weixin').on('ifChecked', function(){
    	$("#input_weibo").iCheck("uncheck");
    	
     });
     $('#input_weibo').on('ifChecked', function(){
    	$("#input_weixin").iCheck("uncheck");
     });

     //返回
     function back_(){
    	 location.href="<%=path%>/view/ui/toDistinctionList";
     }

		/* ckeditor相关   --start */
		/* initSample(); */
		var editor = CKEDITOR.replace('editor', {
			"filebrowserUploadUrl" : "${pageContext.request.contextPath}/api/uploadfile/uploadCKImg",
			enterMode :CKEDITOR.ENTER_BR //换行直接加br
		});


		$('img').error(function(){
		    $(this).attr('src', '<%=path%>/images/marketing/img_load_error.png');
		});

		var choseQrWeixinFlag=false;
		var choseQrWeiboFlag=false;
		var commit_info = "";

	</script>

	<script type="text/javascript">
	    $.fn.dataTable.ext.errMode = 'none';	
     	var access_token=$.cookie('access_token');
	    var cid=$.cookie('cid');
	    var uid=$.cookie('uid');
	    //标题
	    var title;
	    //二维码
	    var weibo_qrcode;
	    var weixin_qrcode;
	    //卡片路径
	    var title_pic;

	    


	    var next_flag;
	    //业务简介
	    var content;
	    //1代表预览0代表保存
	    var status="0";

	    var store_names=new Array();
	    var store_ids=new Array();
	    var type;

		var flag=false;
	    //初始化
	    $(function(){

	    	$(".i-checks").iCheck({checkboxClass:"icheckbox_square-green",radioClass:"iradio_square-green",});

	    	/* activity_id=getQueryString("activity_id"); */
	    	//model_id=getQueryString("model_id");
	    	type="activity";
	    	//modelType=getQueryString("modelType");

	    });


	    //预览
	  	function preview_(){
	  		title=document.getElementById("title").value;
			text_info=CKEDITOR.instances.editor.getData();
			content=$('#content').val();
			if(title!=""){
				if(text_info!=""){
					if(content!=""){
						if(title.length<=18){
							if(content.length<=66){
								if(title_pic!=undefined){
									if($('#input_weibo').is(':checked')){
										weixin_qrcode="";
									}else if($('#input_weixin').is(':checked')){
										weixbo_qrcode="";
									}else{
										weibo_qrcode="";
										weixin_qrcode="";
									}
									status="1";
					  				createActivity();
								}else{
										errorDialog("请上传卡片！","");
								}
							}else{
								errorDialog("业务简介请不要超过66个字！","");
							}
						}else{
							errorDialog("标题不能超过18个字！","");
						}
					}else{
						errorDialog("业务简介不能为空！","");
					}
				}else{
					errorDialog("业务介绍不能为空！","");
				}
			}else{
				errorDialog("标题不能为空！","");
			}
	  	}


		function save() {
			//获取输入的业务标题
			title=document.getElementById("title").value;
			text_info=CKEDITOR.instances.editor.getData();
			text_info=text_info;
			content=$('#content').val();
			if(title!=""){
				if(text_info!=""){
					if(content!=""){
						if(title_pic!=undefined){
							if($('#input_weibo').is(':checked')){
								weixin_qrcode="";
							}else if($('#input_weixin').is(':checked')){
								weixbo_qrcode="";
							}else{
								weibo_qrcode="";
								weixin_qrcode="";
							}
			  				createActivity();
						 }else{
								errorDialog("请上传卡片！","");
						}
					}else{
						errorDialog("业务简介不能为空！","");
					}
				}else{
					errorDialog("业务介绍不能为空！","");
				}
			}else{
				errorDialog("标题不能为空！","");
			}
		}

		//创建业务
		function createActivity(){
			var url = "<%=path%>/distinction/ajaxCreateDistinction";
			$.post(url, {
				/* "access_token" :access_token,
				"cid" : cid,
				"uid" : uid, */
				"title" : title,
				"name" : title,
				"weixinQrcode" : weixin_qrcode,
				"weiboQrcode" : weibo_qrcode,
				"pic" : title_pic,
				"headPic" : title_pic,
				"description" : text_info,
				"content" : content,
				"status":1,
				"distinction":1,
			}, function(data) {
				if (data.status == "200" && status=="0") {
					location.href="<%=path%>/view/ui/toDistinctionList";
				} else if(data.status == "200" && status=="1"){
					location.href="<%=path%>/distinction/toPreview?id="+data.data;
				}else{
					errorDialog("保存失败");
				}
			});
		}

        function fileloadon(upload_type) {
        	var imgUrl = "<%=path%>/images/marketing/img_p.png";
        	//上传微信二维码
            $("#_weixin_qrcode").submit(function () {
            	$("#input_weixin").iCheck("check");
            	if(flag){
            		return ;
            	}
            	flag=true;
                $("#_weixin_qrcode").ajaxSubmit({
                    type: "post",
                    url: "${pageContext.request.contextPath}/api/uploadfile/file",
                    data:{"typename":"filepath"},
                    success: function (data1) {
                        if (data1.realSavePath == undefined){
                            return false;
                        }
                    	weixin_qrcode=data1.realSavePath;
                    	$("#img4").attr('src',weixin_qrcode);
                    	$("#img5").attr('src',imgUrl);
                    	$("#erweima_weixin2").attr('src',weixin_qrcode);
                    	choseQrWeixinFlag=true;
                    },
                    error: function (msg) {
                    	errorDialog("文件上传失败","");
                    }
                });
                return false;
            });

            //上传微博二维码
            $("#_weibo_qrcode").submit(function () {
            	$("#input_weibo").iCheck("check");
            	if(flag){
            		return ;
            	}
            	flag=true;
                $("#_weibo_qrcode").ajaxSubmit({
                    type: "post",
                    url: "${pageContext.request.contextPath}/api/uploadfile/file",
                    data:{"typename":"filepath"},
                    success: function (data1) {
                        if (data1.realSavePath == undefined){
                            return false;
                        }
                    	weibo_qrcode=data1.realSavePath;
                    	$("#img5").attr('src',weibo_qrcode);
                    	$("#img4").attr('src',imgUrl);
                    	$("#erweima_weibo2").attr('src',weibo_qrcode);
                    	choseQrWeiboFlag=true;
                    },
                    error: function (msg) {
                    	errorDialog("文件上传失败","");
                    }
                });
                return false;
            });
            //上传卡片
            $("#pic_").submit(function () {
            	if(flag){
            		return ;
            	}
            	flag=true;
                $("#pic_").ajaxSubmit({
                    type: "post",
                    url: "${pageContext.request.contextPath}/api/uploadfile/file",
                    data:{"typename":"filepath"},
                    success: function (data1) {
                        if (data1.realSavePath == undefined){
                            return false;
                        }
                    	title_pic=data1.realSavePath;
                    	$("#img3").attr('src',title_pic);
                    	$("#img3").attr('src',title_pic);
                    	choseQrWeiboFlag=true;
                    },
                    error: function (msg) {
                    	errorDialog("文件上传失败","");
                    }
                });
                return false;
            });
            switch (upload_type) {

			case "weixin":
				flag=false;
				$("#_weixin_qrcode").submit();
				break;
			case "weibo":
				flag=false;
				$("#_weibo_qrcode").submit();
				break;
			case "pic":
				flag=false;
				$("#pic_").submit();
				break;

			default:
				break;
			}
        }
	</script>
</body>
</html>
